﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security;
using System.Security.Cryptography;
using DBBase;

namespace Business
{
    public partial class Threshold : Form
    {
        public Threshold()
        {
            InitializeComponent();
        }
        private string Encryption(string express)//加密
        {
            CspParameters param = new CspParameters();
            param.KeyContainerName = "gzwk2006";
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
            {
                byte[] plaindate = Encoding.Default.GetBytes(express);
                byte[] encryptdate = rsa.Encrypt(plaindate, false);

                return Convert.ToBase64String(encryptdate);
            }
        }
        //
        private string Decrypt(string cip)//解密
        {
            CspParameters param = new CspParameters();
            param.KeyContainerName = "gzwk2006";
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
            {
                byte[] encryptdate = Convert.FromBase64String(cip);
                byte[] decryptdate = rsa.Decrypt(encryptdate, false);
                return Encoding.Default.GetString(decryptdate);
            }
        }
        public MainForm m_mainform;

        private void but_save_Click(object sender, EventArgs e)
        {
            string shibaifangshi = "锁定";
            if (radio_dj.Checked)
            {
                shibaifangshi = "冻结";
            }
            string zhuangtai = "有效";
            if (radio_sx.Checked)
            {
                shibaifangshi = "失效";
            }
            Query objquery = new Query();
            string ssql = "";
            ssql = string.Format(@"select * from fzsz ");
            DataTable dt = objquery.GetTable(ssql);
            if (dt.Rows.Count < 1)
            {
                ssql = string.Format(@"insert into fzsz 
                                    (ggmc,
                                    mmxgcs,
                                    klzxcd,
                                    klzdcd,
                                    dlsbcsxz,
                                    zdsbcsxz,
                                    yuesu,
                                    mmyxts,
                                    tqtsts,
                                    qzxgts,
                                    zhzdfwcs,
                                    sbfs,
                                    djsjpyl,
                                    zhuantai) values 
                                    ('{0}',
                                    '{1}',
                                    '{2}',
                                    '{3}',
                                    '{4}',
                                    '{5}',
                                    '{6}',
                                    '{7}',
                                    '{8}',
                                    '{9}',
                                    '{10}',
                                    '{11}',
                                    '{12}',
                                    '{13}')",
                                       text_gzmc.Text,
                                       text_mmxgcs.Text,
                                       text_klzxcd.Text,
                                       text_klzdcd.Text,
                                       text_dlsbccxz.Text,
                                       text_zdsbcsxz.Text,
                                       com_yuesu.Text,
                                       text_mmyxts.Text,
                                       text_tqtsts.Text,
                                       text_qzxgts.Text,
                                       text_zhzdfwcs.Text,
                                       shibaifangshi,
                                       text_djsjpyl.Text,
                                       zhuangtai,
                                       text_beizhu.Text);
                //保存操作日记
                m_mainform.savecaozuoriji(ssql, "新增", "系统管理", "新增阀值");
            }
            else
            {
                ssql = string.Format(@"update  fzsz 
                                    set ggmc='{0}',
                                    mmxgcs='{1}',
                                    klzxcd='{2}',
                                    klzdcd='{3}',
                                    dlsbcsxz='{4}',
                                    zdsbcsxz='{5}',
                                    yuesu='{6}',
                                    mmyxts='{7}',
                                    tqtsts='{8}',
                                    qzxgts='{9}',
                                    zhzdfwcs='{10}',
                                    sbfs='{11}',
                                    djsjpyl='{12}',
                                    zhuantai='{13}'",
                                        text_gzmc.Text,
                                        text_mmxgcs.Text,
                                        text_klzxcd.Text,
                                        text_klzdcd.Text,
                                        text_dlsbccxz.Text,
                                        text_zdsbcsxz.Text,
                                        com_yuesu.Text,
                                        text_mmyxts.Text,
                                        text_tqtsts.Text,
                                        text_qzxgts.Text,
                                        text_zhzdfwcs.Text,
                                        shibaifangshi,
                                        text_djsjpyl.Text,
                                        zhuangtai,
                                        text_beizhu.Text);
                //保存操作日记
                m_mainform.savecaozuoriji(ssql, "更新", "系统管理", "更新阀值");
            }
            if (!objquery.UpdateTable(ssql))
            {
                MessageBox.Show("阀值设定失败");
            }
            else
            {
                MessageBox.Show("阀值设定成功");
            }
        }

        private void but_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Threshold_Load(object sender, EventArgs e)
        {
            getdata();
        }
        public void getdata()
        {
            Query objquery = new Query();
            string ssql = "";
            ssql = string.Format(@"select * from fzsz ");
            DataTable dt = objquery.GetTable(ssql);
            if (dt.Rows.Count > 0)
            { 
                text_gzmc.Text=dt.Rows[0]["ggmc"].ToString().Trim();
                text_mmxgcs.Text=dt.Rows[0]["mmxgcs"].ToString().Trim();
                text_klzxcd.Text = dt.Rows[0]["klzxcd"].ToString().Trim();
                text_klzdcd.Text = dt.Rows[0]["klzdcd"].ToString().Trim();
                text_dlsbccxz.Text = dt.Rows[0]["dlsbcsxz"].ToString().Trim();
                text_zdsbcsxz.Text = dt.Rows[0]["zdsbcsxz"].ToString().Trim();
                com_yuesu.Text = dt.Rows[0]["yuesu"].ToString().Trim();
                text_mmyxts.Text = dt.Rows[0]["mmyxts"].ToString().Trim();
                text_tqtsts.Text = dt.Rows[0]["tqtsts"].ToString().Trim();
                text_qzxgts.Text = dt.Rows[0]["qzxgts"].ToString().Trim();
                text_zhzdfwcs.Text = dt.Rows[0]["zhzdfwcs"].ToString().Trim();
             //   shibaifangshi=dt.Rows[i]["sbfs"].ToString().Trim();
                text_djsjpyl.Text = dt.Rows[0]["djsjpyl"].ToString().Trim();
                //  zhuangtai=dt.Rows[i]["zhuantai"].ToString().Trim();
               

             
            }
        }
    }
}
